import { AcGameObject } from '/static/js/ac_game_objects/base.js';
import { Controller } from '/static/js/controller/base.js';

export class GameMap extends AcGameObject {
    constructor(root) {
        super();
        this.root = root; // kof这个div
        this.$canvas = $('<canvas width="1280" height="720" tabindex=0></canvas>'); // jQuery构造的canvas对象
        this.ctx = this.$canvas[0].getContext('2d'); // 得到canvas的绘画上下文context
        this.root.$kof.append(this.$canvas);
        this.$canvas.focus();

        this.controller = new Controller(this.$canvas);

        this.root.$kof.append($(`<div class="kof-head">
            <div class="kof-head-player-0">
                <div>
                    <div></div>
                </div>

            </div>
            <div class="kof-head-timer">60</div>
            <div class="kof-head-player-1">
                <div>
                    <div></div>
                </div>

            </div>
        </div>`));
        this.time_left = 60000;
        this.$timer = this.root.$kof.find(".kof-head-timer");
    }

    start() {

    }

    update() {
        this.time_left -= this.timedelta;
        if (this.time_left < 0) {
            this.time_left = 0;
            let [a, b] = this.root.players;
            if (a.status != 6 && b.status != 6) {
                a.status = b.status = 6;
                a.frame_current_cnt = b.frame_current_cnt = 0;
                a.vx = b.vx = 0;
            }
        }
        this.$timer.text(parseInt(this.time_left / 1000));
        this.render();
    }

    render() {
        this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
        // console.log(this.$canvas.width());
        // this.ctx.fillStyle = 'black';
        // this.ctx.fillRect(0, 0, this.$canvas.width(), this.$canvas.height());
    }
}